package com.aa;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.SlidingDrawer;

public class SlidingLayout extends SlidingDrawer {

	private static final String tag = "SlidingDrawer";
	private int[] OtherID;
	private int contentID;
	private int handleID;
	private boolean isHandle;

	public SlidingLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	public SlidingLayout(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
	{
	    super(paramContext, paramAttributeSet, paramInt);
	}

	public Rect getRectOnScreen(View paramView){
		 Rect localRect = new Rect();
		 int[] arrayOfInt = new int[2];
		 View localView = paramView;
		 if ((paramView.getParent() instanceof View))
		 localView = (View)paramView.getParent();
		 localView.getLocationOnScreen(arrayOfInt);
		 paramView.getHitRect(localRect);
		 localRect.offset(arrayOfInt[0], arrayOfInt[1]);
		 return localRect;
	}
	
	
	@Override
	public boolean onInterceptTouchEvent(MotionEvent paramMotionEvent) {
		this.isHandle = false;
	    int[] arrayOfInt = new int[2];
	    int i = (int)paramMotionEvent.getX();
	    int j = (int)paramMotionEvent.getY();
	    getLocationOnScreen(arrayOfInt);
	    int k = i + arrayOfInt[0];
	    int m = j + arrayOfInt[1];
	    int n = this.handleID;
	    boolean bool1 = false;
	    if (n != 0)
	    {
	      boolean bool2 = getRectOnScreen(findViewById(this.handleID)).contains(k, m);
	      bool1 = false;
	      if (bool2)
	      {
	        this.isHandle = true;
	        bool1 = super.onInterceptTouchEvent(paramMotionEvent);
	      }
	    }
	    return bool1;
		
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		
		 int i = View.MeasureSpec.getMode(widthMeasureSpec);
		    View.MeasureSpec.getSize(widthMeasureSpec);
		    int j = View.MeasureSpec.getMode(heightMeasureSpec);
		    int k = View.MeasureSpec.getSize(heightMeasureSpec);
		    if ((i == 0) || (j == 0))
		      throw new RuntimeException("unspecified");
		    View localView1 = getHandle();
		    View localView2 = getContent();
		    measureChild(localView1, widthMeasureSpec, heightMeasureSpec);
		    localView2.measure(widthMeasureSpec, View.MeasureSpec.makeMeasureSpec(k - localView1.getMeasuredHeight(), j));
		    int m = localView1.getMeasuredHeight() + localView2.getMeasuredHeight();
		    int n = localView2.getMeasuredWidth();
		    if (localView1.getMeasuredWidth() > n)
		      n = localView1.getMeasuredWidth();
		    setMeasuredDimension(n, m);
	}

	@Override
	public boolean onTouchEvent(MotionEvent paramMotionEvent) {
		
		 if (this.isHandle)
		      return super.onTouchEvent(paramMotionEvent);
		    return false;
	}

	public void setOtherID(int[] otherID) {
		OtherID = otherID;
	}

	public void setContentID(int contentID) {
		this.contentID = contentID;
	}

	public void setHandleID(int handleID) {
		this.handleID = handleID;
	}	

}
